
import { Dispatch } from "redux";
export const actions = {
  'CHANGE_NOW': Symbol(),
}

//获取当前时间
export const getNow = function () {
  const now = new Date();
  const hour = now.getHours();
  let second = now.getSeconds();
  let minute = now.getMinutes();
  let milliseconds = now.getMilliseconds();
  let minuteString = minute.toString()
  let secondString = second.toString()
  let millisecondsString = milliseconds.toString()

  if (minute < 10) {
    minuteString = '0' + minute;
  }
  if (second < 10) {
    secondString = '0' + second;
  }
  if (milliseconds < 10) {
    millisecondsString = '00' + milliseconds;
  } else if (milliseconds < 100) {
    millisecondsString = '0' + milliseconds;
  }

  return `${hour}:${minuteString}:${secondString}:${millisecondsString}`;
}


//修改当前时间，同步操作
export const setNow = () => (dispatch: Dispatch) => {
  dispatch({
    type: actions.CHANGE_NOW,
    data: getNow()
  });
};
